<template>
  <div class="app-container" ref="appcontainer">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="工程id" prop="engineeringId">
        <el-input
          v-model="queryParams.engineeringId"
          placeholder="请输入工程id"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="项目id" prop="sampleId">
        <el-input
          v-model="queryParams.sampleId"
          placeholder="请输入项目id"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="姓名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="序号" prop="xuNumber">
        <el-input
          v-model="queryParams.xuNumber"
          placeholder="请输入序号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工程名称" prop="engineeringName">
        <el-input
          v-model="queryParams.engineeringName"
          placeholder="请输入工程名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="职责" prop="zhize">
        <el-input
          v-model="queryParams.zhize"
          placeholder="请输入职责"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="阶段" prop="stage">
        <el-input
          v-model="queryParams.stage"
          placeholder="请输入阶段"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="卷册号" prop="volumeNumber">
        <el-input
          v-model="queryParams.volumeNumber"
          placeholder="请输入卷册号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="校核" prop="checkPerson">
        <el-input
          v-model="queryParams.checkPerson"
          placeholder="请输入校核"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审核" prop="examinePerson">
        <el-input
          v-model="queryParams.examinePerson"
          placeholder="请输入审核"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="职责工日" prop="zhizeWorkday">
        <el-input
          v-model="queryParams.zhizeWorkday"
          placeholder="请输入职责工日"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="校核工日" prop="checkWorkday">
        <el-input
          v-model="queryParams.checkWorkday"
          placeholder="请输入校核工日"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审核工日" prop="examineWorkday">
        <el-input
          v-model="queryParams.examineWorkday"
          placeholder="请输入审核工日"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="完成时间" prop="doneDate">
        <el-input
          v-model="queryParams.doneDate"
          placeholder="请输入完成时间"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="标准工日" prop="standardWorkday">
        <el-input
          v-model="queryParams.standardWorkday"
          placeholder="请输入标准工日"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon=""
          size="mini"
          @click="handleAdd"
          v-hasPermi="['workload:workload:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['workload:workload:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['workload:workload:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['workload:workload:export']"
          v-if="false"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :height="tableHeight" :data="workloadList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" show-overflow-tooltip />
      <el-table-column label="ID" align="center" prop="id" />
      <el-table-column label="工程id" align="center" prop="engineeringId" />
      <el-table-column label="项目id" align="center" prop="sampleId" />
      <el-table-column label="姓名" align="center" prop="name" />
      <el-table-column label="序号" align="center" prop="xuNumber" />
      <el-table-column label="工程名称" align="center" prop="engineeringName" />
      <el-table-column label="职责" align="center" prop="zhize" />
      <el-table-column label="阶段" align="center" prop="stage" />
      <el-table-column label="卷册号" align="center" prop="volumeNumber" />
      <el-table-column label="工作内容" align="center" prop="workContent" />
      <el-table-column label="校核" align="center" prop="checkPerson" />
      <el-table-column label="审核" align="center" prop="examinePerson" />
      <el-table-column label="职责工日" align="center" prop="zhizeWorkday" />
      <el-table-column label="校核工日" align="center" prop="checkWorkday" />
      <el-table-column label="审核工日" align="center" prop="examineWorkday" />
      <el-table-column label="完成时间" align="center" prop="doneDate" />
      <el-table-column label="标准工日" align="center" prop="standardWorkday" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['workload:workload:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['workload:workload:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改工作量统计对话框 -->
    <el-dialog :close-on-click-modal="false" :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="工程id" prop="engineeringId">
          <el-input v-model="form.engineeringId" placeholder="请输入工程id" />
        </el-form-item>
        <el-form-item label="项目id" prop="sampleId">
          <el-input v-model="form.sampleId" placeholder="请输入项目id" />
        </el-form-item>
        <el-form-item label="姓名" prop="name">
          <el-input v-model="form.name" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="序号" prop="xuNumber">
          <el-input v-model="form.xuNumber" placeholder="请输入序号" />
        </el-form-item>
        <el-form-item label="工程名称" prop="engineeringName">
          <el-input v-model="form.engineeringName" placeholder="请输入工程名称" />
        </el-form-item>
        <el-form-item label="职责" prop="zhize">
          <el-input v-model="form.zhize" placeholder="请输入职责" />
        </el-form-item>
        <el-form-item label="阶段" prop="stage">
          <el-input v-model="form.stage" placeholder="请输入阶段" />
        </el-form-item>
        <el-form-item label="卷册号" prop="volumeNumber">
          <el-input v-model="form.volumeNumber" placeholder="请输入卷册号" />
        </el-form-item>
        <el-form-item label="工作内容">
          <editor v-model="form.workContent" :min-height="192"/>
        </el-form-item>
        <el-form-item label="校核" prop="checkPerson">
          <el-input v-model="form.checkPerson" placeholder="请输入校核" />
        </el-form-item>
        <el-form-item label="审核" prop="examinePerson">
          <el-input v-model="form.examinePerson" placeholder="请输入审核" />
        </el-form-item>
        <el-form-item label="职责工日" prop="zhizeWorkday">
          <el-input v-model="form.zhizeWorkday" placeholder="请输入职责工日" />
        </el-form-item>
        <el-form-item label="校核工日" prop="checkWorkday">
          <el-input v-model="form.checkWorkday" placeholder="请输入校核工日" />
        </el-form-item>
        <el-form-item label="审核工日" prop="examineWorkday">
          <el-input v-model="form.examineWorkday" placeholder="请输入审核工日" />
        </el-form-item>
        <el-form-item label="完成时间" prop="doneDate">
          <el-input v-model="form.doneDate" placeholder="请输入完成时间" />
        </el-form-item>
        <el-form-item label="标准工日" prop="standardWorkday">
          <el-input v-model="form.standardWorkday" placeholder="请输入标准工日" />
        </el-form-item>
        <el-form-item label="创建来源" prop="createType">
          <el-select v-model="form.createType" placeholder="请选择创建来源">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="更新来源" prop="updateType">
          <el-select v-model="form.updateType" placeholder="请选择更新来源">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listWorkload, getWorkload, logicDelWorkload, addWorkload, updateWorkload, exportWorkload } from "@/api/workload/workload";

export default {
  name: "Workload",
  data() {
    return {
      tableHeight:0,
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: false,
      // 总条数
      total: 0,
      // 工作量统计表格数据
      workloadList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        engineeringId: null,
        sampleId: null,
        name: null,
        xuNumber: null,
        engineeringName: null,
        zhize: null,
        stage: null,
        volumeNumber: null,
        workContent: null,
        checkPerson: null,
        examinePerson: null,
        zhizeWorkday: null,
        checkWorkday: null,
        examineWorkday: null,
        doneDate: null,
        standardWorkday: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.calHeight()
    },
  watch: {
    'showSearch':'calHeight'
  },
  methods: {
    calHeight () {
          this.$nextTick(() => {
              const rect = this.$refs.appcontainer.getBoundingClientRect();
              let height= this.$refs.queryForm.$el.offsetHeight;
              this.tableHeight = rect.height-height-120;
          })
      },
    /** 查询工作量统计列表 */
    getList() {
      this.loading = true;
      listWorkload(this.queryParams).then(response => {
        this.workloadList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        engineeringId: null,
        sampleId: null,
        name: null,
        xuNumber: null,
        engineeringName: null,
        zhize: null,
        stage: null,
        volumeNumber: null,
        workContent: null,
        checkPerson: null,
        examinePerson: null,
        zhizeWorkday: null,
        checkWorkday: null,
        examineWorkday: null,
        doneDate: null,
        standardWorkday: null,
        createType: null,
        createTime: null,
        updateTime: null,
        delState: null,
        delUser: null,
        delType: null,
        delTime: null,
        createBy: null,
        updateBy: null,
        updateType: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.showSearch=false;
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加工作量统计";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getWorkload(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改工作量统计";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateWorkload(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addWorkload(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return logicDelWorkload(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有工作量统计数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportWorkload(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
    }
  }
};
</script>
